import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/course/csPurchaseMealsOrder/list',
  save='/course/csPurchaseMealsOrder/add',
  edit='/course/csPurchaseMealsOrder/edit',
  deleteOne = '/course/csPurchaseMealsOrder/delete',
  deleteBatch = '/course/csPurchaseMealsOrder/deleteBatch',
  importExcel = '/course/csPurchaseMealsOrder/importExcel',
  exportXls = '/course/csPurchaseMealsOrder/exportXls',
  refundList='/course/csPurchaseMealsOrder/refundList',
  doMealsRefund='/course/csPurchaseMealsOrder/doMealsRefund',
  refundListExportXls = '/course/csPurchaseMealsOrder/refundListExportXls',
  sumMealsRefundList='/course/csPurchaseMealsOrder/sumMealsRefundList',
  findPayMealsOrderPageList='/course/csPurchaseMealsOrder/findPayMealsOrderPageList',
  queryDetailByid='/course/csPurchaseMealsOrder/queryDetailByid',
  wxRevokeMeals='/course/csPurchaseMealsOrder/wxRevokeMeals'
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

export const refundListExportXls = Api.refundListExportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
//退费列表
export const refundList = (params) =>
  defHttp.get({url: Api.refundList, params});


/**
 * 执行退费操作
 * @param params
 */
export const doMealsRefund = (params, handleSuccess) => {
  return defHttp.post({url: Api.doMealsRefund, data: params}, {joinParamsToUrl: true}).then(() => {
  handleSuccess();
});
}


/**
 * 订餐缴费退费统计
 * @param params
 */
export const sumMealsRefundList = (params) =>
  defHttp.get({url: Api.sumMealsRefundList, params});


/**
 * 购买订单列表接口
 * @param params
 */
export const findPayMealsOrderPageList = (params) =>
  defHttp.get({url: Api.findPayMealsOrderPageList, params});
/**
 * 根据订单id查询详情
 * @param params 
 * @returns 
 */
export const queryDetailByid = (params) =>
  defHttp.get({url: Api.queryDetailByid, params});



/**
 * 撤销退款
 * @param params
 */
export const wxRevokeMeals = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认撤销',
    content: '是否撤销选中订单数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.get({url: Api.wxRevokeMeals, params}).then(() => {
        handleSuccess();
      });
    }
  });
}